-
Notifications
You must be signed in to change notification settings - Fork 13.4k
libnative: generic retry() for 64 bit read/write(). #17020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fn retry_base <Int: PartialEq + One + Neg<Int>> | ||
(f: || -> Int, eintr: int) -> Int { | ||
let one: Int = one(); | ||
let minus_one = one.neg(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just write -one::<Int>()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I spent nearly 30 minutes to find a way to call a trait method without &self
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, in this case one
is just a standalone function that wraps the trait. The actual trait method would be called like One::one()
and that currently doesn't allow for type hints (requires UFCS).
Also, the style is for functions to be called module-qualified, e.g. import use std::num;
and call num::one()
and num::zero()
(although that can actually just be !ret.is_zero()
). In this case, you can use the mod
sugar for imports, like use std::num::{mod, One, Zero};
, which brings those to traits into scope, as well as the module (i.e. the mod
is equivalent to use std::num;
)
Thanks for this! Also sorry for my sloppiness in taking too long to make this generic :( |
I cleaned up module imports according to @huonw's suggestion. #[off-topic] A math-savvy person will find the |
I'm getting to understand that Win32/WinSock2 API never calls Windows' equivalent of
|
It's ok to make the windows version of |
97d00d9
to
0117be7
Compare
It should be OK now, but I have no Windows box at hand... |
Thanks @nodakai! Could you squash these commits down as well? |
680be1a
to
3b43506
Compare
Win32/WinSock APIs never call WSASetLastError() with WSAEINTR unless a programmer specifically cancels the ongoing blocking call by a deprecated WinSock1 API WSACancelBlockingCall(). So the errno check was simply removed and retry() became an id function on Windows. Note: Windows' equivalent of SIGINT is always handled in a separate thread: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682541%28v=vs.85%29.aspx "CTRL+C and CTRL+BREAK Signals" Also, incidentally rename a type parameter and clean up some module imports.
3b43506
to
52e99cb
Compare
@alexcrichton Noted,
all squashed into 52e99cb |
The current implementation of
retry()
cannot handle, say,write()
of >2 GB data because it truncates the return value of the closure parameter intoc_int
which is (almost always) only 32 bit.This is my first code to use traits... I hope
#[inline]
works as intended.I think
mkerr_libc()
is still causing bugs here and there; I'll fix them later.